<template>
  <div class="content">
    <Tabs v-model="name" type="card" :animated="false" @on-click="onChangeTab">
      <TabPane label="APP金刚区设置" name="1"></TabPane>
      <TabPane label="APP获客工具菜单设置" name="2"></TabPane>
      <TabPane label="APP模块设置" name="3"></TabPane>
    </Tabs>
    <Row justify="end" align="middle">
      <Col><Button type="primary" @click="addItem">新增</Button></Col>
    </Row>
    <dt-grid ref="table" :list="list" />

    <update-modal ref="update" />
  </div>
</template>

<script>
  import Column from './opt/Column.js'
  import updateModal from './components/update-modal.vue'
  import mgr from '@/biz/backStage/appMenuConfig.js'

  export default {
    components: {
      updateModal
    },
    data() {
      return {
        name: '1',
        info: {
          module1: [],
          module2: [],
          module3: []
        },
        list: []
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.$refs.table.init(this, new Column(this, this.name))
        this.update()
      })
    },
    methods: {
      update() {
        mgr.list().then((res) => {
          this.info = res
          this.list = this.info[`module${this.name}`]
        })
      },
      onMark(row) {
        mgr.update(row)
      },
      addItem() {
        let data = {
          id: null,
          menuCode: '',
          menuIcon: '',
          menuName: '',
          mark: 0,
          type: this.name,
          sort: null
        }
        this.$refs.update.show(data, this.update)
      },
      onEdit(item) {
        this.$refs.update.show(item, this.update)
      },
      // 切换tab
      onChangeTab() {
        this.$refs.table.clearFilter()
        this.$refs.table.init(this, new Column(this, this.name))
        this.list = this.info[`module${this.name}`]
      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    padding: 20px;
  }
</style>
